package org.javahispano.javacup.tacticas_aceptadas.maxtor.org.javahispano.javacup.modelo.mio;


public class VectorFis {

	private double[] origen = null;
	private double[] destino = null;
	
	public double[] getDestino() {
		return destino;
	}


	public void setDestino(double[] destino) {
		this.destino = destino;
	}


	public double[] getOrigen() {
		return origen;
	}


	public void setOrigen(double[] origen) {
		this.origen = origen;
	}

	

	public double[] simular(int pasos, double [] factorDisminucion) {
	// el paso 1 es el actual	
		
		double [] simulacion = new double[destino.length];
		double [] componentes = getComponentes();
		
		for (int i=0; i<destino.length; i++) {
			// S = a(1 - pow(r,n)) / (1 - r)
			double a = componentes[i];
			double r = factorDisminucion[i];
			simulacion[i] = (a * (1- Math.pow(r,pasos)) / (1 - r)) + origen[i];
		}	
		return simulacion;
	}
	
	
	public double getModulo() {
		double result = 0;
		for (int i=0; i<destino.length; i++) {
			result += Math.pow(destino[i]-origen[i],2);
		}
		return Math.sqrt(result);
	}
	
	public double[] getComponentes() {
		double[] result = new double[destino.length];
		for (int i=0; i<destino.length; i++) {
			result[i] = destino[i]-origen[i];
		}
		return result;
	}
	

	public boolean equalsOrigen(VectorFis vector) {
		if (vector == null) return false;
		double[] array = vector.getOrigen();
		if (array==null) return origen==null;
		for (int i=0;i<origen.length;i++) {
			if (array[i]!=origen[i]) return false;
		}
		return true;
	}
	public boolean equalsDestino(VectorFis vector) {
		if (vector == null) return false;
		double[] array = vector.getDestino();
		if (array==null) return destino==null;
		for (int i=0;i<destino.length;i++) {
			if (array[i]!=destino[i]) return false;
		}
		return true;
	}
	
	public boolean equals(VectorFis vector) {
		if (vector == null) return false;
		double[] array = vector.getOrigen();
		if (array!=null && origen !=null) {
			for (int i=0;i<origen.length;i++) {
				if (array[i]!=origen[i]) return false;
			}
		}
		array = vector.getDestino();
		if (array!=null && destino !=null) {
			for (int i=0;i<destino.length;i++) {
				if (array[i]!=destino[i]) return false;
			}
		}	
		return true;
	}


	public String toString()
	{
	    StringBuilder retValue = new StringBuilder();
	    retValue.append("VectorFis ( ").append("o = (");
	    if (origen==null) retValue.append("null)");
	    else {
	    	for (int i=0;i<origen.length;i++) retValue.append(origen[i]).append(",");
	    	retValue.deleteCharAt(retValue.length()-1).append(")");
	    }
	    retValue.append(" d = (");
	    if (destino==null) retValue.append("null)");
	    else {
	    	for (int i=0;i<destino.length;i++) retValue.append(destino[i]).append(",");
	    	retValue.deleteCharAt(retValue.length()-1).append(")");
	    }
	    
	    return retValue.append(" )").toString();
	}
	
}
